import { createStore } from 'vuex'
import user from '@/store/modules/user.ts'
import sheet from '@/store/modules/sheet.ts'
import goods from '@/store/modules/goods.ts'
import challenge from '@/store/modules/challenge'
import personCenter from '@/store/modules/personCenter'

export default createStore({
  state: {
    token: sessionStorage.getItem('token'),
    u: JSON.parse(sessionStorage.getItem('user')),
    admin: sessionStorage.getItem('isAdmin')
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
      sessionStorage.setItem('token', token)
    },
    SET_USER: (state, u) => {
      state.u = u
      sessionStorage.setItem('user', JSON.stringify(u))
    },
    SET_ADMIN: (state, admin) => {
      state.admin = admin
      sessionStorage.setItem('isAdmin', admin)
    },
    REMOVE_INFO: (state) => {
      state.token = ''
      state.u = {}
      state.admin = ''
      sessionStorage.setItem('token', '')
      sessionStorage.setItem('user', JSON.stringify(''))
      sessionStorage.setItem('isAdmin', '')
    }
  },
  actions: {
  },
  modules: {
    user,
    sheet,
    goods,
    challenge,
    personCenter
  }
})
